import { _decorator, Component, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('gameCamera')
export class gameCamera extends Component {
    /** 相机跟随的目标节点 */
    public ndFollowTarget: Node = null!;
    /** 初始相机世界坐标 */
    private _oriCameraWorPos: Vec3 = new Vec3();
    /** 目标相机世界坐标 */
    private _targetCameraWorPos: Vec3 = new Vec3();
    /** 目标相机世界坐标 */
    private _curCameraWorPos: Vec3 = new Vec3();






    /** 重置相机 */
    public resetCamera() {
        console.log('this.node',this._oriCameraWorPos)
        this._targetCameraWorPos.set(this._oriCameraWorPos);
    }
    start() {
        console.log('this.node',this.node)
        this._oriCameraWorPos = this.node.worldPosition.clone();
    }

    /** 更新相机位置 */
    lateUpdate() {
        if (!this.ndFollowTarget || !this.ndFollowTarget.worldPosition) {
            return;
        }
        this._targetCameraWorPos = this._targetCameraWorPos.lerp(this.ndFollowTarget.worldPosition, 0.5);
        this._curCameraWorPos.set(this._oriCameraWorPos.x + this._targetCameraWorPos.x, this._oriCameraWorPos.y, this._oriCameraWorPos.z + this._targetCameraWorPos.z);
        this.node.setWorldPosition(this._curCameraWorPos);
    }
}


